<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "write_question".
 *
 * @property integer $id
 * @property integer $tnum
 * @property string $info
 * @property string $question
 * @property string $reading_content
 * @property string $url
 * @property string $hearing_content
 * @property integer $class1_id
 * @property integer $class2_id
 * @property integer $num
 * @property string $diff
 * @property string $index_img_url
 * @property integer $class_num
 * @property string $class_name
 *
 * @property WritePerson[] $writePeople
 * @property Class1 $class1
 * @property Class2 $class2
 */
class WriteQuestion extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'write_question';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['tnum', 'info', 'question', 'class1_id', 'class2_id', 'num', 'class_num', 'class_name'], 'required'],
            [['tnum', 'class1_id', 'class2_id', 'num', 'class_num'], 'integer'],
            [['info', 'question', 'reading_content', 'hearing_content'], 'string'],
            [['url', 'index_img_url', 'class_name'], 'string', 'max' => 255],
            [['diff'], 'string', 'max' => 32],
            [['class1_id'], 'exist', 'skipOnError' => true, 'targetClass' => Class1::className(), 'targetAttribute' => ['class1_id' => 'id']],
            [['class2_id'], 'exist', 'skipOnError' => true, 'targetClass' => Class2::className(), 'targetAttribute' => ['class2_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'tnum' => 'Tnum',
            'info' => 'Info',
            'question' => 'Question',
            'reading_content' => 'Reading Content',
            'url' => 'Url',
            'hearing_content' => 'Hearing Content',
            'class1_id' => 'Class1 ID',
            'class2_id' => 'Class2 ID',
            'num' => 'Num',
            'diff' => 'Diff',
            'index_img_url' => 'Index Img Url',
            'class_num' => 'Class Num',
            'class_name' => 'Class Name',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getWritePeople()
    {
        return $this->hasMany(WritePerson::className(), ['write_question_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getClass1()
    {
        return $this->hasOne(Class1::className(), ['id' => 'class1_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getClass2()
    {
        return $this->hasOne(Class2::className(), ['id' => 'class2_id']);
    }
}
